package com.huifaapp.mall.selectImage;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.AbsListView;
import android.widget.GridView;

public class PhotoGridView extends GridView {

	ILoadingImage iLoadingImage;
	int firstVisible;
	int visibleItem;

	public PhotoGridView(Context context) {
		super(context);
		into();

	}

	public PhotoGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
		into();
	}

	public PhotoGridView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		into();
	}

	public void into() {
		setOnScrollListener(onScrollListener);
	}

	public void setiLoadingImage(ILoadingImage iLoadingImage) {
		this.iLoadingImage = iLoadingImage;
	}

	OnScrollListener onScrollListener = new OnScrollListener() {

		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
				iLoadingImage.loadingimag(firstVisible, visibleItem);
			}
		}

		@Override
		public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
			firstVisible = firstVisibleItem;
			visibleItem = visibleItemCount;
		}
	};

	public interface ILoadingImage {
		public void loadingimag(int firstVisibleItem, int visibleItemCount);
	}

}
